package com.api.action.v1.pms;

import com.admin.entity.Station;
import com.admin.entity.Terminal;
import com.admin.service.impl.StationServiceImpl;
import com.admin.service.impl.TerminalServiceImpl;
import com.alibaba.fastjson.JSONObject;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 绿云
 *
 */
@RestController
@RequestMapping("/api/greencloud/")
public class GreenCloudAction {

    @Autowired
    private StationServiceImpl stationService;

    @Autowired
    private TerminalServiceImpl terminalService;

    @PostMapping("/postPms")
    public Map post(@RequestBody String content)
    {
        System.out.println(content);
        //{"rescode":"200","resDesc":"访问成功"}
        Map map = new HashMap();
        map.put("rescode",200);
        map.put("resDesc","访问成功");

        JSONObject jsonObject = JSONObject.parseObject(content);
        String hotelCode = jsonObject.getString("hotelCode");  //酒店代码
        String  bizType   = jsonObject.getString("bizType");  //业务类型
        String  name      = jsonObject.getString("name");     //顾客名字
        String  rmno      = jsonObject.getString("rmno");//房号
        String  hotelDescript = jsonObject.getString("hotelDescript"); //酒店名称
        String  sex   = jsonObject.getString("sex");
        sex = "1".equals(sex)? "先生":"女士";

        Station station  = stationService.findByPms(hotelCode);
        if (station==null) {
            station = stationService.findByPms(hotelDescript);
        }
        if (station==null){
            map.put("resDesc","酒店代码没有设置");
            return map;
        }
        Terminal t = terminalService.getTerminalByRoom(station,rmno);
        if (t==null){
            map.put("resDesc","房间号不存设置");
            return map;
        }
        switch (bizType){
            case "CHECKIN":  //入住
            case "GUESTCHG": //修改信息
            case "RMCHG": //换房
                t.setTerminalPmsName(name+sex);
                break;
            case "CHECKOUT": //退房
                t.setTerminalPmsName(null);
                break;
        }

        terminalService.updateById(t);
        return map;
    }
}
